//扩展forEach each方法既可以遍历数组也可以遍历类数组，对象
/*
辨别循环对象是数组还是对象 Array.
是数组就用forEach方法
是对象 就forin
*/
let arr = [10, 20, 40]
let obj = { name: 'zs', age: 10 }
console.log(obj instanceof Array)
console.log(Array.isArray(arr))


let each = function (obj, callback) {
    if (Array.isArray(obj)) {
        return obj.forEach(callback)
    }
    for (let key in obj) {
        callback(obj[key], obj)
    }

}
let res = each(obj, (element, index) => console.log(element))
console.log(res)